﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using NHibernate.Linq;
using Entities;
using RepositoriesInterfaces;

using NHibernate;

namespace Repositories
{
    public class StudyPlanItemRepository : BaseRepository<StudyPlanItem>, IStudyPlanItemRepository
    {
        public StudyPlanItemRepository(ISession session)
        {
            this._session = session;
        }
        
        public IList<StudyPlanItem> GetByDirectionId(int DirectionId)
        {
            _session.BeginTransaction();
            IList<StudyPlanItem> SPItemList = (from s in _session.Query<StudyPlanItem>()
                                               where s.Direction.Id == DirectionId
                                               select s).Distinct().ToList();
            _session.Transaction.Commit();

            return SPItemList; 
        }

        public IList<StudyPlanItem> GetSameSPIItem(int SPItemId)
        {
            StudyPlanItem tempItem = GetByID(SPItemId);
            _session.BeginTransaction();            
            IList<StudyPlanItem> SPItemList = (from s in _session.Query<StudyPlanItem>()
                                               where s != tempItem
                                               where s.Direction != tempItem.Direction
                                               where s.Discipline == tempItem.Discipline
                                               where s.Department == tempItem.Department
                                               where s.Semestr == tempItem.Semestr
                                               where s.HoursLecture == tempItem.HoursLecture
                                               where s.HoursPractice == tempItem.HoursPractice
                                               where s.HoursLaboratory == tempItem.HoursLaboratory
                                               where s.HoursSRS == tempItem.HoursSRS
                                               where s.TypeSRS == s.TypeSRS
                                               select s).Distinct().ToList();
            _session.Transaction.Commit();

            return SPItemList; 
        }
    }
}